package com.mini.framework.communicate.mina.adapter;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.apache.mina.filter.codec.demux.MessageEncoder;

import com.mini.framework.communicate.mina.protocol.Encoder;
import com.mini.framework.communicate.mina.protocol.Msg;

public class MsgEncoderAdapter<T extends Msg> implements MessageEncoder<T> {
	
	
	
	private Encoder encoder;
	
	public MsgEncoderAdapter(Encoder encoder){
		this.encoder = encoder;
	}
	
	/**
	 * 编码对象.
	 * 
	 */
	public void encode(IoSession session, T msg, ProtocolEncoderOutput out){
		if(msg instanceof Msg){
			Msg sendmsg = (Msg)msg;
			IoBuffer buff = encoder.encode(sendmsg);
			out.write(buff);
		}
	}

	

}
